<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('志愿者管理列表')" />
</head>
<body class="gray-bg">
    <div class="container-div">
        <div class="row">
            <!--搜索框-->
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>志愿者编号：</p>
                                <input type="text" name="volunteerCode"/>
                            </li>
                            <li>
                                <p>姓名：</p>
                                <input type="text" name="volunteerName"/>
                            </li>
                            <li>
                                <p>部门：</p>
                                <select name="sectorId">
                                    <option value="">所有</option>
                                    <option th:each="item:${sectorList}"
                                            th:value="${item.sectorId}"
                                            th:text="${item.sectorName}">
                                    </option>
                                </select>
                            </li>
                            <li>
                                <p>学院名称：</p>
                                <select name="academyId">
                                    <option value="">所有</option>
                                    <option th:each="item:${academyList}"
                                             th:value="${item.academyId}"
                                             th:text="${item.academyName}">
                                    </option>
                                </select>
                            </li>
                            <li>
                                <p>最高学历：</p>
                                <select name="volunteerDegree" th:with="type=${@dict.getType('degree')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}"
                                            th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}">
                                    </option>
                                </select>
                            </li>
                            <li class="select-time">
                                <p>入队时间：</p>
                                <input type="text" class="time-input" id="startTime" style="width: 133px" placeholder="请选择开始时间" name="params[beginVolunteerDate]"/>
                                <span>至</span>
                                <input type="text" class="time-input" id="endTime" style="width: 133px" placeholder="请选择结束时间" name="params[endVolunteerDate]"/>
                            </li>
                            <li>
                                <p>状态：</p>
                                <select name="memberState" th:with="type=${@dict.getType('member_state')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}"
                                            th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}">
                                    </option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <!--组件操作-->
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="team:volunteermanage:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="team:volunteermanage:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="team:volunteermanage:import">
                    <i class="fa fa-upload"></i> 导入
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="team:volunteermanage:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>

            <!--志愿者管理信息-->
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table">
                    <thead>
                        <tr>
                            <th data-checkbox="true"></th>
                            <th data-formatter="fm_rowIndex" data-align="center">序号</th>
                            <th data-field="volunteerCode" data-align="center">志愿者编号</th>
                            <th data-field="volunteerName" data-align="center">姓名</th>
                            <th data-field="sexName" data-formatter="fm_sex" data-align="center">性别</th>
                            <th data-field="sectorName" data-align="center">部门</th>
                            <th data-field="dutiesName" data-align="center">担任职务</th>
                            <th data-field="volunteerAcademy" data-align="center">所在学院</th>
                            <th data-field="volunteerProfession" data-align="center">专业</th>
                            <th data-field="volunteerNo" data-align="center">学号</th>
                            <th data-field="volunteerDegree" data-formatter="fm_degree" data-align="center">学历</th>
                            <th data-field="volunteerDate" data-align="center"  data-formatter="fm_date">入队时间</th>
                            <th data-field="serveTime" data-align="center">服务时长</th>
                            <th data-field="serveTimes" data-align="center">服务次数</th>
                            <th data-field="memberState" data-formatter="fm_state" data-align="center">状态</th>
                            <th data-formatter="fm_commands" data-width="280px" data-align="center">操作</th>
                        </tr>
                    </thead>
                </table>
            </div>

        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('team:volunteermanage:edit')}]];            //编辑
        var removeFlag = [[${@permission.hasPermi('team:volunteermanage:remove')}]];        //删除
        var detailFlag = [[${@permission.hasPermi('team:volunteermanage:detail')}]];        //详情
        var blacklistFlag = [[${@permission.hasPermi('team:volunteermanage:blacklist')}]];  //加入黑名单
        var prefix = ctx + "vtsp/volunteermanage";              //志愿者管理
        var sexData = [[${@dict.getType('sys_user_sex')}]];     //获取字典中的数据：性别
        var degreeData = [[${@dict.getType('degree')}]];        //获取字典中的数据：学历
        var stateData = [[${@dict.getType('member_state')}]];   //获取字典中的数据：状态

        //初始化表格参数
        $(function()
        {
            var options =
                {
                    url: prefix + "/list",                  //志愿者管理页面
                    createUrl: prefix + "/add",             //添加
                    updateUrl: prefix + "/edit/{id}",       //编辑
                    removeUrl: prefix + "/remove",          //删除
                    exportUrl: prefix + "/export",          //导出
                    detailUrl: prefix + "/detail/{id}",     //详情
                    importUrl: prefix + "/import",          //导入
                    importTemplateUrl: prefix + "/importTemplate",  //导入模版
                    modalName: "志愿者",
                    uniqueId: "volunteerId"
                };
            $.table.init(options);
        });

        //格式化日期
        function fm_date(value, row ,index)
        {
            return dateFormat("YYYY-mm-dd", value);
        }

        //格式化数据字典：性别
        function fm_sex(value, row ,index)
        {
            return $.table.selectDictLabel(sexData, value);
        }
        //格式化数据字典：学历
        function fm_degree(value, row ,index)
        {
            return $.table.selectDictLabel(degreeData, value);
        }
        //格式化数据字典：状态
        function fm_state(value, row ,index)
        {
            return $.table.selectDictLabel(stateData, value);
        }

        //操作按钮
        function fm_commands(value, row, index)
        {
            var actions = [];
            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.volunteerId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.volunteerId + '\')"><i class="fa fa-remove"></i>删除</a>');
            actions.push('<a class="btn btn-primary btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.modal.openFull(\'' + '志愿者详情' + '\',\'' + prefix + '/detail/' + row.volunteerId + '\')"><i class="fa fa-search"></i>详情</a>');
            actions.push('<a class="btn btn-warning btn-xs ' + blacklistFlag + '" href="javascript:void(0)" onclick="toBlacklist(\'' + row.volunteerId + '\')"><i class="fa fa-trash"></i>加入黑名单</a>');
            return actions.join('');
        }

        //拉入黑名单
        function toBlacklist(volunteerId)
        {
            //窗体确认
            $.modal.confirm("确定将该志愿者加入黑名单吗？",function()
            {
                //点击确认
                let blacklistUrl = prefix + "/blacklist";           //黑名单志愿者
                let blackVolunteer = {"volunteerId":volunteerId};   //黑名单志愿者ID
                //上传信息
                $.operate.submit(blacklistUrl, "post", "json", blackVolunteer);
                $.modal.alertSuccess("操作成功！");
            });
        }
    </script>
    <!-- 导入区域 -->
    <script id="importTpl" type="text/template">
        <form enctype="multipart/form-data" class="mt20 mb10">
            <div class="col-xs-offset-2">
                <input type="file" id="file" name="file"/>
                <div class="mt10 pt5">
                    <p style="color: black;">数据模版下载：<a onclick="$.table.importTemplate()" class="btn btn-default btn-sm"> 下载模板</a></p>
                </div>
                <div class="pull-left mt10" style="color: red;">
                    提示：仅允许导入“xls”或“xlsx”格式文件！
                </div>
            </div>
        </form>
    </script>
</body>
</html>